﻿// -------------------------------------------------------------------------
//    @FileName         :    NFCityMapInst.h
//    @Author           :    Gao.Yi
//    @Date             :    2025-09-17
//    @Email			:    445267987@qq.com
//    @Module           :    NFCityMapInst
//    @Desc             :
//
// -------------------------------------------------------------------------

#pragma once

#include "CityDescEx.h"
#include "NFCityMapGrid.h"
#include "NFCityNpcMgr.h"
#include "NFComm/NFObjCommon/NFObject.h"
#include "NFLogicCommon/NFLogicShmTypeDefines.h"

class NFCityNeighborGrid;
class NFICityWorldObjectFunc;
class NFCityWorldObject;

#define GUILD_BATTLE_DESTORY_TIME_OUT 1200//20 * 60

class NFCityMapInst : public NF_OBJECT_TEMPLATE_MACRO(NFCityMapInst, EOT_CITY_MAP_INST_ID, NFObject)
public:
    NFCityMapInst();
    ~NFCityMapInst() override;
    int CreateInit();
    int ResumeInit();

public:
    int Init(int iMapDescId);
    int OnTimer(int timeId, int callCount) override;
    int Tick();
    int Fin();
public:
    int MovePos(NFCityWorldObject* pWorldObj, const Proto_Vector3& position, int iDirection);
    int EnterMap(NFCityWorldObject* pWorldObj, const Proto_Vector3& position, int iDirection);
    int LeaveMap(NFCityWorldObject* pWorldObj);
    int EnterMapBornPos(NFCityWorldObject* pWorldObj);
    void GetEnterPos(Proto_Vector3& oEnterPos, int& iDirection);
    int IteratorWorldObject(NFICityWorldObjectFunc* pFunc, ECityWorldListType eListType);
    int GetNeighborGrids(NFCityWorldObject* pWorldObj, NFCityNeighborGrid& oGrids);

public:
    void SetCreateTime(uint64_t ullTime) { m_ullCreateTime = ullTime; }
    uint64_t GetCreateTime() { return m_ullCreateTime; }
    void SetDungeonId(uint64_t ullDungeonID) { m_ullDungeonId = ullDungeonID; }
    uint64_t GetDungeonId() { return m_ullDungeonId; }
    bool IsPositionValid(const Proto_Vector3& position);
    int GetMapDescId() const { return m_iMapDescId; }
    int GetMapGridId(int iGridIdx);
    NFCityNpcMgr* GetNpcMgr() { return &m_oNpcMgr; }

private:
    int InitMapGrid(int iMapDescID);
    int InitMapNpc();
    bool IsNeedDestroy();
private:
    int GetGridObjId(const Proto_Vector3& position);
    bool IsMapGridIndexValid(int iGridIndex) { return iGridIndex >= 0 && iGridIndex < m_iMaxGridNum && iGridIndex < MAX_MAP_GRID_NUM; }

private:
    int m_iMapDescId;
    uint64_t m_ullDungeonId;
    Proto_Vector3 m_oMapBeginPos;
    Proto_Vector3 m_oMapEndPos;
    int m_iMapXGridNum;
    int m_iMapZGridNum;
    int m_iMaxGridNum;
    int m_iMapGridSize;

    Proto_Vector3 m_oMapEnterPos;
    int m_iEnterDirection;

    int m_aiMapGrid[MAX_MAP_GRID_NUM];

    uint64_t m_ullCreateTime;
    uint32_t m_iPlayerCnt;

    NFCityNpcMgr m_oNpcMgr;
};
